/**
 * Foxit Software Inc.
 * Copyright(C) 2005-2014, all rights reserved.
 * The following code is copyrighted and contains proprietary information
 * and trade secrets of Foxit Software Inc.

 * Description: LinkAnnotHandler
 * Author: shaojie zhuo
 * Update: shaojie zhuo (2014-05-20 10:49)
 */
define(function (require, exports, module) {
    WebPDF.LinkAnnotHandler = function (readerApp) {
        this.readerApp = readerApp;
    };

    WebPDF.LinkAnnotHandler.prototype =
    {
        getType: function () { return "Link" ;  },

        canAnswer: function (pAnnot, bAllowSelectTextTool)
        {
            var currentTool = this.readerApp.getCurToolHandler();
            if (currentTool) {
                var toolName = currentTool.getName();
                if (toolName === WebPDF.Tools.TOOL_NAME_HAND){
                    return true;
                }
            }
            return false;
        },
        canMove: function (subType) {
            return false;
        },
        moveAnnot: function(pageView, selectedAnnot,
                            offsetX, offsetY ,newPosX, newPosY){
            return false;
        },
        deleteAnnot: function(pageView, annot){

        },
        onDraw: function(pageView, selectedAnnot, isRedraw, extraScale){
        },
        onSelected: function(pageView, annot){

        },
        onDeSelected: function(pageView, annot){

        },
        onFocus: function(pageView, annot){
        },
        onLButtonDown: function(pageView,annot, event){
            var action = annot.getAction();
            if (action != null) {
                switch (action.getActionType()) {
                    case "GoTo":  {
                        var destination = action.getPDFDestination();
                        if (destination != null) {
                            pageView.getDocView().gotoPageByDestination(destination);
                            return false;
                        }
                    }
                        break;
                    case "URI": {
                        var linkUrl = event.target.getAttribute("link-uri");
                        linkUrl && window.open(linkUrl);
                    }
                        break;
                    default: break;
                }
            }
            else {
                var destination = action.getPDFDestination();
                if (destination != null) {
                    pageView.getDocView().gotoPageByDestination(destination);
                    return false;
                }
            }
            return false;
        },
        onLButtonUp: function(pageView,annot, event){
        },
        OnLButtonDblClk: function(pageView,event,annot){
        },
        onMouseOver: function(pageView, annot, event){
        },
        onMouseLeave : function (pageView, annot, event) {
        },
        onUpdatePosition: function(pageView, annot, visibleRect){

        }
    };



    return WebPDF.LinkAnnotHandler;
});